package function;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import UserDatabase.House;
import UserDatabase.HouseDatabase;

public class UpdateHouseFrame extends JFrame{
	
	private JLabel l_hno,l_state;
	private JTextField t_hno,t_state;
	private JButton b_confirm,b_reset;
	HouseDatabase h = new HouseDatabase();
	
	public UpdateHouseFrame() {
		this.setTitle("更新房间状态");
		this.setSize(430,260);
		this.setLocation(500, 300);
		this.setLayout(null);
		init();
		this.setVisible(true);
		this.setResizable(false);
	}
	
	public void init() {
		Font fontB = new Font("宋体",Font.BOLD,12);
		
		l_hno = new JLabel("房间号",JLabel.CENTER);
		l_hno.setFont(fontB);
		l_state = new JLabel("房间状态（已入户/未入户）",JLabel.CENTER);
		l_state.setFont(fontB);
		
		
		t_hno = new JTextField();
		t_hno.setFont(fontB);
		t_state = new JTextField();
		t_state.setFont(fontB);
		
		b_confirm = new JButton("确认");
		b_confirm.setFont(fontB);
		b_confirm.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				String hno = t_hno.getText();
				String state = t_state.getText();
				House house = new House(hno,state);
				h.update(house);
				JPanel f = new JPanel();
				JOptionPane.showMessageDialog(f,"修改成功,刷新页面可显示！","提示框",JOptionPane.WARNING_MESSAGE);
				setVisible(false);
			}
			
		});
		
		b_reset = new JButton("重置");
		b_reset.setFont(fontB);
		b_reset.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				t_hno.setText(null);
				t_state.setText(null);
			}
			
		});
		
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(3,2,5,5));
		p.add(l_hno);
		p.add(t_hno);
		p.add(l_state);
		p.add(t_state);
		p.add(b_confirm);
		p.add(b_reset);
		p.setBounds(35,10,350,200);
		
		this.add(p);
		
	}
	
}
